<template>
  <el-dialog
    :title="!this.dataForm.urId ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm"  label-width="80px">
    <el-form-item label="用户昵称" prop="urName">
      <el-input v-model="dataForm.urName" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="用户密码" prop="urPassword">
      <el-input v-model="dataForm.urPassword" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="urCreateTime">
      <el-input v-model="dataForm.urCreateTime" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="用户名" prop="urUsername">
      <el-input v-model="dataForm.urUsername" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="用户头像" prop="urAvatar">
 <singleupload v-model="dataForm.urAvatar"/>
      <!-- <el-input v-model="dataForm.urAvatar" placeholder=""></el-input> -->
    </el-form-item>
    <el-form-item label="余额" prop="urWallet">
      <el-input v-model="dataForm.urWallet" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="支付密码" prop="urPaymentPassword">
      <el-input v-model="dataForm.urPaymentPassword" placeholder="支付密码"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import singleupload from "@/components/upload/singleUpload.vue";
    import api from "@/api/modules/cbbuser";
  export default {
    components:{
       singleupload
    },
    data () {
      return {
        visible: false,
        dataForm: {
          urId: 0,
          urName: '',
          urPassword: '',
          urCreateTime: '',
          urUsername: '',
          urAvatar: '',
          urWallet: '',
          urPaymentPassword: ''
        },
        dataRule: {
          urName: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          urPassword: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          urCreateTime: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          urUsername: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          urAvatar: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          urWallet: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          urPaymentPassword: [
            { required: true, message: '支付密码不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.urId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          api.info(this.dataForm.urId).then(({data}) => {
              if (data) {
                this.dataForm.urName = data.cbbUser.urName
                this.dataForm.urPassword = data.cbbUser.urPassword
                this.dataForm.urCreateTime = data.cbbUser.urCreateTime
                this.dataForm.urUsername = data.cbbUser.urUsername
                this.dataForm.urAvatar = data.cbbUser.urAvatar
                this.dataForm.urWallet = data.cbbUser.urWallet
                this.dataForm.urPaymentPassword = data.cbbUser.urPaymentPassword
              }
            })
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
    var parms= {
'urId': this.dataForm.urId || undefined,
'urName': this.dataForm.urName,
'urPassword': this.dataForm.urPassword,
'urCreateTime': this.dataForm.urCreateTime,
'urUsername': this.dataForm.urUsername,
'urAvatar': this.dataForm.urAvatar,
'urWallet': this.dataForm.urWallet,
'urPaymentPassword': this.dataForm.urPaymentPassword        }
        api.updateAdd(parms,this.dataForm.urId).then((res) => {
              if (res.code==200) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
